package cn.edu.njust.service;

import cn.edu.njust.dao.UserDAOImpl;
import cn.edu.njust.entity.Login;

/**
 * LoginService:实现登录密码的校验
 */


public class LoginService {
    public int login(String username, String password){
        UserDAOImpl dao = new UserDAOImpl();
        Login user = dao.findByName(username);
        if(user == null){   //找不到用户
            return 0;               //返回0说明用户不存在
        }else{              //存在该用户
            if(password.equals(user.getPassword())){    //密码正确
                return 1;
            }else{          //密码错误
                return 2;
            }
        }
    }

    public Login findByName(String username){
        UserDAOImpl dao = new UserDAOImpl();
        return dao.findByName(username);
    }

}

